

package Cliente;

import callProcs.ProcsCliente;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


public class BusquedaCliente extends javax.swing.JFrame {

    
    public java.sql.ResultSet rs ;
    public String consulta = new String();
    public ProcsCliente verCliente = new ProcsCliente();
    /** Creates new form NewJFrame */
    public BusquedaCliente() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        rNombre = new javax.swing.JRadioButton();
        rCedula = new javax.swing.JRadioButton();
        rDpi = new javax.swing.JRadioButton();
        tBusqueda = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tCliente = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(bufete.BufeteApp.class).getContext().getResourceMap(BusquedaCliente.class);
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        rNombre.setText(resourceMap.getString("rNombre.text")); // NOI18N
        rNombre.setName("rNombre"); // NOI18N
        rNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rNombreActionPerformed(evt);
            }
        });

        rCedula.setText(resourceMap.getString("rCedula.text")); // NOI18N
        rCedula.setName("rCedula"); // NOI18N
        rCedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rCedulaActionPerformed(evt);
            }
        });

        rDpi.setText(resourceMap.getString("rDpi.text")); // NOI18N
        rDpi.setName("rDpi"); // NOI18N
        rDpi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rDpiActionPerformed(evt);
            }
        });

        tBusqueda.setText(resourceMap.getString("tBusqueda.text")); // NOI18N
        tBusqueda.setName("tBusqueda"); // NOI18N
        tBusqueda.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tBusquedaKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addComponent(rNombre)
                .addGap(68, 68, 68)
                .addComponent(rCedula)
                .addGap(69, 69, 69)
                .addComponent(rDpi)
                .addContainerGap(108, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(114, Short.MAX_VALUE)
                .addComponent(tBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 459, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(91, 91, 91))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(rNombre)
                    .addComponent(rDpi)
                    .addComponent(rCedula))
                .addGap(18, 18, 18)
                .addComponent(tBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(39, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Nombre Completo", "No. Cedula", "No. DPI", "Dirección", "No. Telefono"
            }
        ));
        tCliente.setName("tCliente"); // NOI18N
        tCliente.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tClienteFocusGained(evt);
            }
        });
        jScrollPane1.setViewportView(tCliente);
        tCliente.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("tCliente.columnModel.title0")); // NOI18N
        tCliente.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("tCliente.columnModel.title1")); // NOI18N
        tCliente.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("tCliente.columnModel.title2")); // NOI18N
        tCliente.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("tCliente.columnModel.title3")); // NOI18N
        tCliente.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("tCliente.columnModel.title4")); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 612, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(73, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(273, 273, 273)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(37, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(38, 38, 38)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(115, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tBusquedaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tBusquedaKeyReleased
    Vector<String> tableHeaders = new Vector<String>();
    Vector tableData = new Vector();
    tableHeaders.add("Nombre"); 
    tableHeaders.add("No. Cedula");
    tableHeaders.add("No. DPI");
    tableHeaders.add("Direccion");
    tableHeaders.add("Telefono");
       
        try {
          rs = verCliente.VerdatosCliente(consulta+tBusqueda.getText()+"%'");
          while (rs.next()){
             
        Vector<Object> oneRow = new Vector<Object>();
        oneRow.add(rs.getObject("Nombre"));
        oneRow.add(rs.getObject("No. Cedula"));
        oneRow.add(rs.getObject("Dpi_cliente"));
        oneRow.add(rs.getObject("Direccion"));
        oneRow.add(rs.getObject("Telefono"));
        tableData.add(oneRow);
       }
      tCliente.setModel(new DefaultTableModel(tableData, tableHeaders));
          
        } catch (SQLException ex) {
            Logger.getLogger(BusquedaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
       
      
    }//GEN-LAST:event_tBusquedaKeyReleased

    private void rNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rNombreActionPerformed
                
        if(rNombre.isSelected()){
            rCedula.setSelected(false);
            rDpi.setSelected(false);
            consulta = "WHERE concat(Nombre_cliente,' ', Apellido_cliente) LIKE '%";
        }
        
        
        
        
    }//GEN-LAST:event_rNombreActionPerformed

    private void rCedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rCedulaActionPerformed
       if(rCedula.isSelected()){
            rNombre.setSelected(false);
            rDpi.setSelected(false);
            consulta = "WHERE concat(No_registro_cliente,No_orden_cliente) LIKE '%";
        }
        
    }//GEN-LAST:event_rCedulaActionPerformed

    private void rDpiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rDpiActionPerformed
        if(rDpi.isSelected()){
            rNombre.setSelected(false);
            rCedula.setSelected(false);
            consulta = "WHERE Dpi_cliente LIKE '%";
        }
    }//GEN-LAST:event_rDpiActionPerformed

    private void tClienteFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tClienteFocusGained
            
        
        JOptionPane.showMessageDialog(null," ehh =)" );
    
    }//GEN-LAST:event_tClienteFocusGained

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new BusquedaCliente().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JRadioButton rCedula;
    private javax.swing.JRadioButton rDpi;
    private javax.swing.JRadioButton rNombre;
    private javax.swing.JTextField tBusqueda;
    private javax.swing.JTable tCliente;
    // End of variables declaration//GEN-END:variables
}
